<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="${ctx}/css/common.css" />
	<jsp:include page="../inc.jsp"></jsp:include>
	<jsp:include page="../head.jsp"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge" />
<title>订单查询</title>
<style>
		select,input{
			height:18px;
			border:1px solid #77b2e0;
			border-radius: 3px;
		}
		.searchBox{
			width:1140px;
			height:40px;
			margin-top:15px;
			margin-left:20px;
		}
		select{
			height:20px;
			margin-right:20px;	
			border:1px solid #77b2e0;				
		}
		.query{
			float:right;
		}
		.searchDetail{
			border-collapse: collapse;
			text-align: center;
			border:1px solid #dedede;
		}
		.searchDetail th{
			font-size: 12px;
			font-weight: normal;
			border:1px solid #dedede;
			height:30px;
			color:#3989c8;
			/* min-width: 10%; */
		}
		.searchDetail td{
			border:1px solid #dedede;
			height:30px;
			min-width:40px;
			text-align:center;
			/* padding:0 5px; */
		}
		/*使按钮居中*/
		.autoBox{
			width:250px;
			height:26px;
			margin:15px auto; 
		}
		input::-ms-clear{display:none;}
		.pageUl li{
			float:left;
			cursor:pointer;			
		}
		.tableOntab td{
			height:37px;
			border-right:none;
		}
		.tableOntab .borderNone{
			border-bottom:none;
		}
	</style>
<script type="text/javascript">
	$(function() { 
		//加载表格信息
		dataGrid = $('#orderTable').datagrid({
			url:'${ctx}/search/getBuyerList?orderType=0&temp='+Math.random(),
			width:1600,
			striped : true,
			singleSelect : true,
			idField : 'flightIdList',
			pageList : [5,10,20],
			//sortName : 'id',
			//sortOrder : 'asc',
			method : 'get',
			toolbar:'#toolbar',
			pagination:true,
			sortName:'orderCreateTime',
			sortOrder:'desc',
			columns:[[
			{
				width : '80',
				title : 'id',
				field : 'id',
				hidden : true,
				sortable : true
			},
			{
				width : '220',
				title : '订单号',
				align : 'center',
				field : 'orderNumber',
				sortable : true,
			},{
				width : '80',
				title : '航班号',
				align : 'center',
				field : 'airlineId',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:60px;"><tr><td>'+((row.list))[0].airlineNumber+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:60px;"><tr><td>'+((row.list))[0].airlineNumber+'</td>'+'</tr><tr>'+'<td class="borderNone">'+((row.list))[1].airlineNumber+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '140',
				title : '出发',
				align : 'center',
				field : 'charterTypeStr',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].deptCity+'('+(row.list)[0].deptCode+')</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].deptCity+'('+(row.list)[0].deptCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].deptCity+'('+(row.list)[1].deptCode+')'+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '140',
				title : '到达',
				align : 'center',
				field : 'scheduleId',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].arrCity+'('+(row.list)[0].arrCode+')</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].arrCity+'('+(row.list)[0].arrCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].arrCity+'('+(row.list)[1].arrCode+')'+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '80',
				title : '出发日期',
				align : 'center',
				field : 'scheduleIdStr',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:80px;"><tr><td>'+(row.list)[0].deptDate+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:80px;"><tr><td>'+(row.list)[0].deptDate+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].deptDate+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '55',
				title : '出发时刻',
				align:'center',
				field : 'journeyType',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].deptTime)+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].deptTime)+'</td>'+'</tr><tr>'+'<td class="borderNone">'+CommonConverter.formatFlightTime((row.list)[1].deptTime)+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '55',
				title : '到达时刻',
				align:'center',
				field : 'toDate',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						
						if(row.list.length == 1){
							var backIntervalDay=(row.list)[0].intervalDay;
							var _backIntervalDay="";
							if (backIntervalDay >= 1){
								_backIntervalDay="+"+backIntervalDay;
							}; 
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].arrTime)+_backIntervalDay+'</td></tr></table>';
						}else if(row.list.length == 2){
							var toIntervalDay=(row.list)[0].intervalDay;
							var backIntervalDay=(row.list)[1].intervalDay;
							var _toIntervalDay="";
							var _backIntervalDay="";
							if (toIntervalDay >= 1){
								_toIntervalDay="+"+toIntervalDay;
							}; 
							if (backIntervalDay >= 1){
								_backIntervalDay="+"+backIntervalDay;
							}; 
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].arrTime)+_toIntervalDay+
							'</td>'+'</tr><tr>'+'<td class="borderNone">'+CommonConverter.formatFlightTime((row.list)[1].arrTime)+_backIntervalDay+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '100',
				title : '单价',
				align:'center',
				field : 'sellingPrice',
			},{
				width : '50',
				title : '数量',
				align:'center',
				field : 'purchQuantity',
			},{
				width : '50',
				title : '总价',
				align:'center',
				field : 'sum',
			},{
				width : '130',
				title : '支付截止时间',
				align:'center',
				field : 'paymentDeadline',
			},{
				width : '130',
				title : '最晚出票时间',
				align:'center',
				field : 'ticketingDeadline',
			},{
				width : '120',
				title : '状态',
				align:'center',
				field : 'placeHolder',
				formatter : function(value,row){
					var orderStatus=CommonConverter.toOrderBizStatusStr(row.orderStatus);
					return orderStatus;
				}
			},{
				width : '250',
				title : '操作',
				align:'center',
				field : 'fareSaleStr',
				formatter:function(value,row){
					var str = '<span class="mynewBtn" onclick=orderDtail("'+row.orderNumber+'")>查看详情</span>';
					if(row.orderStatus==0){
						str += '<span class="mynewBtn" onclick=orderTicket("'+row.orderNumber+'")>出票申请</span>'
						+'<span class="mynewBtn" onclick=cancelOrder("'+row.orderNumber+'")>取消订单';
					}else if(row.orderStatus == 4){
						str += '<span class="mynewBtn" onclick=getTickedDetail("'+row.orderNumber+'")>查看票号</span>';
					};
					return str;
				}
			}
			] ]
		});
		//点击查询 重新加载列表
		$("#query").click(function(){
			//出发到达城市清空处理
			alsoempty($("#homecity_name"),$("#_startCity"));
			alsoempty($("#getcity_name"),$("#_endCity"));
			//获取参数
			var orderNumber=$("#_orderNumber").val();
			var pssOrderNumber=$("#_pssNumber").val();
			var orderStatus=$("#orderStatus").val();
			var toStartAirportCode=$("#_startCity").val();
			var toEndAirportCode=$("#_endCity").val();
			var toStartDate=$("#_startTime").datebox('getValue');
			var toEndDate=$("#_endTime").datebox('getValue');
			var buyerName=$("#buyerName").val();
			var sellerName=$("#sellerName").val();
			var financeStatus=$("#financeStatus").val();
			if(typeof(toStartAirportCode) == 'undefined'){
				toStartAirportCode = "";
			};
			if(typeof(toEndAirportCode) == 'undefined'){
				toEndAirportCode = "";
			};
			$('#orderTable').datagrid('load',{"orderNumber":orderNumber,"pssOrderNumber":pssOrderNumber,"orderStatus":orderStatus,"toStartAirportCode":toStartAirportCode,"toEndAirportCode":toEndAirportCode,"toStartDate":toStartDate,"toEndDate":toEndDate,"buyerName":buyerName,"sellerName":sellerName,"financeStatus":financeStatus,"temp":Math.random()});
			$('#orderTable').datagrid('unselectAll');//清除全选
		});
	}); 
	
	
	
	
	//订单支付
	function OrderPay(orderNumber) {
		layer.open({
			type: 2,
			title: ['订单管理-支付票款','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.3,
			yes: function(index, layero) {
				layer.close(index);
			},
			area: ['1000px', '450px'],
			content: ['${ctx}/order/orderPay/'+orderNumber, 'no'], //iframe的url，no代表不显示滚动条
			end:function(){
				$('#orderTable').datagrid("reload");
				$('#orderTable').datagrid('unselectAll');//清除全选
			}
		});
	}; 
	//查看票号弹出框
	function getTickedDetail(orderNumber) {
		//console.log(orderNumber)
		layer.open({
			type: 2,
			title: ['订单管理-查看票号','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.3,
			area: ['1020px', '500px'],  
			content: ['${ctx}/order/orderTickets/'+orderNumber, 'no'], //iframe的url，no代表不显示滚动条
		});
	};
	//出票申请
	function orderTicket(orderNumber){
		layer.open({
			type: 2,
			title: ['订单管理-出票申请','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.3,
			area: ['1200px', '500px'],
			content: ['${ctx}/np/orderPassengerWait/'+orderNumber, 'no'], //iframe的url，no代表不显示滚动条
			success: function(layero, index){
			  layer.full(index);
			},
			end:function(){
				$('#orderTable').datagrid("reload");
				$('#orderTable').datagrid('unselectAll');//清除全选
			}
		});
	}
	//取消订单
	function cancelOrder(orderNumber){
		layer.confirm("确认要取消订单【"+orderNumber+"】吗？"
			, {title:['取消订单','background-color:#00B2EE; color:#fff;'],area: ['400px', '150px']}
			, function(index){
				$.ajax({
				    type:'get',
				    url: '${ctx}/order/cancel/'+orderNumber+'?t='+Math.random(),
				    success:function(data){
				    	if(data.status==1){
					        layer.alert('取消订单成功！'
					        	,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}
					        	, function(index){
					        		$('#orderTable').datagrid("reload");
					        		$('#orderTable').datagrid('unselectAll');//清除全选
									layer.close(index);
								});
					    }
					    else{
					      layer.alert(data.message);
					    }
				    },
				    error:function(msg){
				    	layer.alert("请检查您的网络连接，然后重试！");
				    }
				}); 
				
				layer.close(index);
			}
		);
	}; 
	//查看详情
	function orderDtail(orderNumber){
		layer.open({
			type: 2,
			title: ['订单管理-查看详情','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.3,
			area: ['1200px', '500px'],
			content: ['${ctx}/order/detail/'+orderNumber, 'no'], //iframe的url，no代表不显示滚动条
			success: function(layero, index){
			  layer.full(index);
			}
		});
	};
	//如果为空  对应的文本框为空
	function alsoempty(a,b){
		if(a.val() == "中文/拼音"){
			b.val("");
		};
	};
</script>
</head>
<body>
<div style="margin:0 10px;width:100%">
		<div class='searchBox'>
				订单号：<input style='width:120px;' class="easyui-textbox" id="_orderNumber" />
				状态：
				<select id="orderStatus" style="width: 73px;">
					<option value="-1">所有订单</option>
					<option value="0">待支付</option>
					<option value="2">待出票</option>
					<option value="4">出票完成</option>
					<option value="5">已取消</option>
				</select>
				出发城市：
				<input type="text" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="_startCity" mod_notice_tip="中文/拼音" />
				<input id="_startCity" name="_startCity" type="hidden" value="" />
				到达城市：
				<input type="text" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="_endCity" mod_notice_tip="中文/拼音" />
				<input id="_endCity" name="_endCity" type="hidden" value="" />
				出发时间 ：<input class="easyui-datebox" id="_startTime" style="width: 120px" />
				至<input class="easyui-datebox" id="_endTime" style="width: 120px" />
				<button class='query' id="query" >查询</button>
		</div>
	<div style="width:100%;overflow: hidden">
		<table id="orderTable" class="easyui-datagrid" data-options="border:false"></table>
	</div>
</div>
<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>